/**
 * TB_ZHGX_CARDREPLACEINFO
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-12-04 09:49:56
 *</pre>
 */
$(function() {
	cardReplaceInfo  = new CardReplaceInfo();
	cardReplaceInfo.init();
	
	formUrl = cardReplaceInfo.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#cardReplaceInfoGrid",// 列表对象
			PAGER : "#cardReplaceInfoPager",// 列表分页
			FORM : '#cardReplaceInfoForm',// 表单form
			FORMGET : '#cardReplaceInfoFormGet'// 表单form
			
	};
	/**
	 * TB_ZHGX_CARDREPLACEINFO 对象
	 * @returns {CardReplaceInfo}
	 */
	CardReplaceInfo = function() {
		//定义属性
	};

	/**
	 * 方法
	 */
	CardReplaceInfo.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
				
			}
			if ($(this.consts.FORM).length > 0){//表单
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/CardReplace/cardReplaceInfo/listJson.htm',
						pager :this.consts.PAGER,
						colNames: ['主键','类型','旧卡号','新卡号','用户ID',/*'操作者','操作时间'*/'同步标识1','同步日期1'/*,'同步标识2','同步日期2','同步标识3','同步日期3','EXT1','EXT2','EXT3'*/,'管理'],
				        colModel: [{
				                 	   name:'id',
				                	   index: 'ID'

										
				                	 	,hidden:true,key:true
				                	 	}, {
				                 	   name:'changetype',
				                	   index: 'CHANGETYPE'

										
				                	 					                	 	}, {
				                 	   name:'oldcardnum',
				                	   index: 'OLDCARDNUM'

										
				                	 					                	 	}, {
				                 	   name:'newcardnum',
				                	   index: 'NEWCARDNUM'

										
				                	 					                	 	}, {
				                 	   name:'userid',
				                	   index: 'USERID'

										
				                	 					                	 	},/* {
				                 	   name:'operater',
				                	   index: 'OPERATER'

										
				                	 					                	 	}, {
				                 	   name:'operatetime',
				                	   index: 'OPERATETIME'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	},*/ {
				                 	   name:'issync1',
				                	   index: 'ISSYNC1'

										
				                	 					                	 	}, {
				                 	   name:'sync1date',
				                	   index: 'SYNC1DATE'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}/*, {
				                 	   name:'issync2',
				                	   index: 'ISSYNC2'

										
				                	 					                	 	}, {
				                 	   name:'sync2date',
				                	   index: 'SYNC2DATE'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'issync3',
				                	   index: 'ISSYNC3'

										
				                	 					                	 	}, {
				                 	   name:'sync3date',
				                	   index: 'SYNC3DATE'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'ext1',
				                	   index: 'EXT1'

										
				                	 					                	 	}, {
				                 	   name:'ext2',
				                	   index: 'EXT2'

										
				                	 					                	 	}, {
				                 	   name:'ext3',
				                	   index: 'EXT3'

										
				                	 					                	 	}*/ , {
									name : '__manage',
									width : 30,
									sortable:false,
									classes:'rowOps',
									formatter : 'manage',
									formatoptions :[{
										label:'编辑',
										classes:'btn btn-primary fa fa-edit',
										action:__ctx+'/rdp/CardReplace/cardReplaceInfo/edit.htm?id={id}'
									},/*{
										label:'删除',
										classes:'btn btn-primary fa fa-remove',
										action:__ctx+'/rdp/CardReplace/cardReplaceInfo/remove.htm?id={id}'
									},*/{
										label:'明细',
										classes:'btn btn-primary fa fa-detail',
										action: __ctx+'/rdp/CardReplace/cardReplaceInfo/get.htm?id={id}'
									}]
								} ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});
		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/CardReplace/cardReplaceInfo/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();